# 斐波那契迭代器
class FibIterator(object):

    def __init__(self, n):
        self.n = n
        # current用来保存当前生成到数列中的第几个数了
        self.current = 0
        # num1用来保存前前一个数，初始值为数列中第一个数0
        self.num1 = 0
        # num2用来保存前一个数，初始值为数列中的第二个数1
        self.num2 = 1

    def __iter__(self):
        return self

    def __next__(self):
        if self.current < self.n:
            num = self.num1
            self.num1, self.num2 = self.num2, self.num1 + self.num2
            self.current += 1
            return num
        else:
            raise StopIteration


fib = FibIterator(10)
for a in fib:
    print(a)
# 0
# 1
# 1
# 2
# 3
# 5
# 8
# 13
# 21
# 34